<template>
 <div class="wrapper" ref="wrapper">
   <div class="content">
     <slot></slot>
   </div>
 </div>
</template>

<script>

  import BSScroll from 'better-scroll'

  export default {
    name: "Scroll",
    data:function(){

      return {
        scroll:null
      }
    },
    mounted() {

      this.bsScrollInit();
    },
    methods:{

      bsScrollInit(){

        this.scroll = new BSScroll(this.$refs.wrapper,{

          scrollY:true,
          //开启div点击事件
          click:true,
          //是否监听事件滚动
          probeType:3,
          pullUpLoad:true,
        });
        this.scroll.on('scroll',(pos)=>{

          this.$emit('scrollPosChange',pos)
        });
        this.scroll.on('pullingUp',()=>{
          this.$emit('pullingUp');

          setTimeout(()=>{
            this.scroll.finishPullUp();
          },1000);

        });
      },
      scrollToPos(x,y,time){

        console.log(y);
        this.scroll.scrollTo(x,y,time)
      },
      scrollRefresh(){

       if (this.scroll){
         this.scroll.refresh();
       }
      }
    }
  }
</script>

<style scoped>

  .wrapper{

    width: 100%;
    overflow: hidden;
  }

</style>
